
//顶点对象
function cube_vao_gen(gl, cubehalflength, programInfo_cube){
	
	//buffers
	const VAO_cube = gl.createVertexArray();
	gl.bindVertexArray(VAO_cube);
	const VBO_cube = gl.createBuffer();
	gl.bindBuffer(gl.ARRAY_BUFFER, VBO_cube);
	{
	let cube = [cubehalflength, cubehalflength, cubehalflength, 0.0, 0.0, 1.0,	0.5, 1.0, 
			-cubehalflength, cubehalflength, cubehalflength, 0.0, 0.0, 1.0,	0.25, 1.0,
			-cubehalflength, -cubehalflength, cubehalflength, 0.0, 0.0, 1.0,	0.25, 0.75,
			cubehalflength, cubehalflength, cubehalflength, 0.0, 0.0, 1.0,		0.5, 1.0,
			-cubehalflength, -cubehalflength, cubehalflength, 0.0, 0.0, 1.0,	0.25, 0.75,
			cubehalflength, -cubehalflength, cubehalflength, 0.0, 0.0, 1.0,	0.5, 0.75,
		
			-cubehalflength, cubehalflength, -cubehalflength, 0.0, 0.0, -1.0,	0.25, 0.5,
			cubehalflength, cubehalflength, -cubehalflength, 0.0, 0.0, -1.0,	0.5, 0.5,
			cubehalflength, -cubehalflength, -cubehalflength, 0.0, 0.0, -1.0,	0.5, 0.25,
			-cubehalflength, cubehalflength, -cubehalflength, 0.0, 0.0, -1.0,	0.25, 0.5,
			cubehalflength, -cubehalflength, -cubehalflength, 0.0, 0.0, -1.0,	0.5, 0.25,
			-cubehalflength, -cubehalflength, -cubehalflength, 0.0, 0.0, -1.0,	0.25, 0.25,
		
			cubehalflength, cubehalflength, cubehalflength, 1.0, 0.0, 0.0, 	0.25, 0.75,
			cubehalflength, -cubehalflength, cubehalflength, 1.0, 0.0, 0.0, 	0.0, 0.75, 
			cubehalflength, -cubehalflength, -cubehalflength, 1.0, 0.0, 0.0, 	0.0, 0.5,
			cubehalflength, cubehalflength, cubehalflength, 1.0, 0.0, 0.0, 	0.25, 0.75,
			cubehalflength, -cubehalflength, -cubehalflength, 1.0, 0.0, 0.0, 	0.0, 0.5,
			cubehalflength, cubehalflength, -cubehalflength, 1.0, 0.0, 0.0, 	0.25, 0.5,
		
			-cubehalflength, cubehalflength, cubehalflength, 0.0, 1.0, 0.0, 	0.5, 0.75,
			cubehalflength, cubehalflength, cubehalflength, 0.0, 1.0, 0.0, 	0.25, 0.75, 
			cubehalflength, cubehalflength, -cubehalflength, 0.0, 1.0, 0.0, 	0.25, 0.5,
			-cubehalflength, cubehalflength, cubehalflength, 0.0, 1.0, 0.0, 	0.5, 0.75,
			cubehalflength, cubehalflength, -cubehalflength, 0.0, 1.0, 0.0, 	0.25, 0.5,
			-cubehalflength, cubehalflength, -cubehalflength, 0.0, 1.0, 0.0, 	0.5, 0.5,
			
			-cubehalflength, -cubehalflength, cubehalflength, -1.0, 0.0, 0.0, 	0.75, 0.75,
			-cubehalflength, cubehalflength, cubehalflength, -1.0, 0.0, 0.0, 	0.5, 0.75, 
			-cubehalflength, cubehalflength, -cubehalflength, -1.0, 0.0, 0.0, 	0.5, 0.5,
			-cubehalflength, -cubehalflength, cubehalflength, -1.0, 0.0, 0.0, 	0.75, 0.75,
			-cubehalflength, cubehalflength, -cubehalflength, -1.0, 0.0, 0.0, 	0.5, 0.5,
			-cubehalflength, -cubehalflength, -cubehalflength, -1.0, 0.0, 0.0, 	0.75, 0.5,
			
			cubehalflength, -cubehalflength, cubehalflength, 0.0, -1.0, 0.0, 	1, 0.75,
			-cubehalflength, -cubehalflength, cubehalflength, 0.0, -1.0, 0.0, 	0.75, 0.75, 
			-cubehalflength, -cubehalflength, -cubehalflength, 0.0, -1.0, 0.0, 	0.75, 0.5,
			cubehalflength, -cubehalflength, cubehalflength, 0.0, -1.0, 0.0, 	1, 0.75,
			-cubehalflength, -cubehalflength, -cubehalflength, 0.0, -1.0, 0.0, 	0.75, 0.5,
			cubehalflength, -cubehalflength, -cubehalflength, 0.0, -1.0, 0.0 ,	1, 0.5];//立方体顶点数据
			
			
	//纹理坐标计算
	for(let row = 0;row< 3;row += 1){
		for(let col = 0;col < 3;col += 1){
			let i = row * 3 + col;
			if(i >= 6){
				break;
			}
			cube[i * 48 +6] = (col + 1.0) / 3.0;
			cube[i * 48 +7] = (3.0 - row) / 3.0;
			
			cube[i * 48 + 8 +6] = (col) / 3.0;
			cube[i * 48 + 8 +7] = (3.0 - row) / 3.0;
			
			cube[i * 48 + 16 +6] = (col) / 3.0;
			cube[i * 48 + 16 +7] = (3.0 - row - 1.0) / 3.0;
			
			
			cube[i * 48 + 24 +6] = (col + 1.0) / 3.0;
			cube[i * 48 + 24 +7] = (3.0 - row) / 3.0;
			
			cube[i * 48 + 32 +6] = (col) / 3.0;
			cube[i * 48 + 32 +7] = (3.0 - row - 1.0) / 3.0;
			
			cube[i * 48 + 40 +6] = (col + 1.0) / 3.0;
			cube[i * 48 + 40 +7] = (3.0 - row - 1.0) / 3.0;
		}
	}
	
		
	gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(cube), gl.STATIC_DRAW);
	}

		
	
	gl.vertexAttribPointer(
		programInfo_cube.attribLocations.vertexPosition,
		3,
		gl.FLOAT,
		false,
		32,
		0,
	);
	gl.vertexAttribPointer(
		programInfo_cube.attribLocations.normPosition,
		3,
		gl.FLOAT,
		false,
		32,
		12,
	);
	gl.vertexAttribPointer(
		programInfo_cube.attribLocations.coordPosition,
		2,
		gl.FLOAT,
		false,
		32,
		24,
	);
	gl.enableVertexAttribArray(programInfo_cube.attribLocations.vertexPosition);
	gl.enableVertexAttribArray(programInfo_cube.attribLocations.normPosition);
	gl.enableVertexAttribArray(programInfo_cube.attribLocations.coordPosition);
	
	
	return VAO_cube;
}